const {addRole,getRoleList,ModifyUserRoleById,DeleteRoleById}=require("../service/role_service")
class RoleController{
    async createRole(ctx, next) {
        let {role_name,description} = ctx.request.body
        try {
            await addRole(role_name,description)
            ctx.body = {
                status: 200,
                message:"创建角色成功"
            }
        } catch (error) {
            console.log(error)
        }
    }
    async getRoleList(ctx, next) {
        try {
            let roleList=await getRoleList()
            ctx.body = {
                status: 200,
                roleList,
                message:"获取角色列表成功"
            }
        } catch (error) {
            console.log(error)
        }
    }
    async EditRole(ctx, next) {
        let { id } = ctx.params;
        let {role_name,description}=ctx.request.body
        try {
            await ModifyUserRoleById(id,role_name,description)
            ctx.body = {
                status: 200,
                message:"修改角色信息成功"
            }
        } catch (error) {
            console.log(error)
        }
    }
    async DeleteRole(ctx, next) {
        let { id } = ctx.params;
        try {
            await DeleteRoleById(id)
            ctx.body = {
                status: 200,
                message:"删除角色成功"
            }
        } catch (error) {
            console.log(error)
        }
    }
    
}
module.exports=new RoleController()